#!/bin/bash

# 复制状态检查脚本

MASTER_HOST="mysql-master"
SLAVE_HOSTS=("mysql-slave1" "mysql-slave2" "mysql-backup")

echo "=== MySQL复制状态检查 ==="
echo "检查时间: $(date)"
echo

# 检查主库状态
echo "主库状态:"
docker exec $MASTER_HOST mysql -u root -proot123 -e "SHOW MASTER STATUS\G" | grep -E "(File|Position|Executed_Gtid_Set)"

echo

# 检查从库状态
for slave in "${SLAVE_HOSTS[@]}"; do
    echo "从库 $slave 状态:"
    docker exec $slave mysql -u root -proot123 -e "SHOW REPLICA STATUS\G" | grep -E "(Replica_IO_Running|Replica_SQL_Running|Seconds_Behind_Master|Last_Error)"
    echo
done
